//
//  PrimitiveSequence.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/7.
//

import Foundation
import RxSwift
import Moya
import ObjectMapper

extension PrimitiveSequence where Trait == SingleTrait, Element == Response {
    func mapObject<T: BaseMappable>(_ type: T.Type) -> Single<T> {
        return flatMap { response in
            do {
//                let Json = try  response.data
                let object = try response.mapObject(T.self)
                return .just(object)
            } catch {
                return .error(error)
            }
        }
    }
//    func mapObject<T: BaseMappable>(_ type: BaseResponse<T>.Type) -> Single<BaseResponse<T>> {
//           return flatMap { response -> Single<BaseResponse<T>> in
//               do {
//                   let base = try response.mapObject(type)
//                   return .just(base)
//               } catch {
//                   return .error(error)
//               }
//           }
//       }
    
    
    
    func mapArray<T: BaseMappable>(_ type: T.Type) -> Single<[T]> {
        return flatMap { response in
            do {
                let array = try response.mapArray(T.self)
                return .just(array)
            } catch {
                return .error(error)
            }
        }
    }
}
